package org.xg.study.pd.store.impl;

import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xg.study.pd.coupon.CouponResult;
import org.xg.study.pd.coupon.CouponService;
import org.xg.study.pd.store.ICommodity;

import java.util.Map;

/**
 * @author CMG
 * @version 1.0
 * @cLassName CouponCommodityService
 * @description 优惠券发放接口
 * @date 2021/9/9 9:57
 **/
public class CouponCommodityService implements ICommodity {
    private Logger logger = LoggerFactory.getLogger(CouponCommodityService.class);

    private CouponService couponService = new CouponService();

    @Override
    public void sendCommodity(String uId, String commodityId, String bizId, Map<String, String> extMap) throws Exception {
        CouponResult couponResult = couponService.sendCoupon(uId, commodityId, bizId);
        logger.info("请求参数【优惠券】 => uId:{}, commodityId:{}, bizId:{}, extMap:{}", uId, commodityId, bizId, JSONObject.toJSON(extMap));
        logger.info("测试结果【优惠券】：{}", JSONObject.toJSON(couponResult));
        if (!"0000".equals(couponResult.getCode())) {
            throw new RuntimeException(couponResult.getInfo());
        }
    }
}
